'use strict';

import * as actions from '../../actions/zhekou1_edit_items';

// 对页面prop 数据进行管理
const initialState = {
  creating: false,
  error:false,
  loginError:false,
  message:"",
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction ) {

  switch (action.type) {
    case actions.LOAD_START:
      return Object.assign({}, state, {
        creating:true,
        error:false,
        loginError:false
      });
	  break;
    case actions.LOAD_ERR:
      return Object.assign({}, state, {
        creating:false,
		error:true,
		loginError:action.loginFalse,
		message:action.message
      });
	  break;
    case actions.GET_LIST_DONE:
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
		data:action.data,
        activityId:action.activityId
      });
	  break;
    case actions.CLEAR_LIST:
      return Object.assign({}, state, {
        creating:true,
        error:false,
        loginError:false,
		data:false
      });
	  break;
    case actions.CLOSE_DIALOG:
      return Object.assign({}, state, {
		error:action.visible,
        loginError:false
      });
	  break;
    case actions.RESET_ITEM:
      return Object.assign({}, state, {});
	  break;
    case actions.REMOVE_ITEM:
	  state.data.items.item.map((item,key)=>{
		  if(item.detail_id == action.detail_id){
			  state.data.items.item.splice(key,1);
		  }
	  })
      return Object.assign({}, state, {
		  	creating: false,
			error:false,
			loginError:false,
	  });
	  break;
    default:
      return state;
  }
}

